<!DOCTYPE html>
<html>

<head>

    {include file="Public/header"}

</head>

<body class="white-bg" style="padding: 0;margin:0">

<div class="ibox">
    <div class="ibox-content">
        <form action="" class="form-horizontal" id="add">
            <div class="form-group">
                <label class="col-xs-3 control-label">分区负责人：</label>
                <div class="col-xs-9">
                    <p class="form-control-static">{$data.zoning}</p>
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group">
                <label class="col-xs-3 control-label">省份负责人：</label>
                <div class="col-xs-9">
                    <p class="form-control-static">{$data.provice}</p>
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group">
                <label class="col-xs-3 control-label">城市负责人：</label>
                <div class="col-xs-9">
                    <p class="form-control-static">{$data.city}</p>
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group">
                <label class="col-xs-3 control-label">业务人员：</label>
                <div class="col-xs-7">
                    <!--<span class="help-block m-b-none">说明文字</span>-->
                    <div class="input-group">
                        <input name="stuff" id="testNoBtn" type="text" placeholder="请输入关键字或空格查询" class="form-control" value="">
                        <div class="input-group-btn">
                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu dropdown-menu-right" role="menu">
                            </ul>
                        </div>
                        <div class="renyuan" id="renyuan">
                            {if is_array($data.stuff)}
                            {volist name="data.stuff" id="row"}
                            <span class="ren"  data-id="{$row.id}">{$row.em_name}<span class="close">×</span></span>
                            {/volist}
                            {/if}
                        </div>
                    </div>

                </div>
                <div class="col-xs-2">
                    <a href="javascript:;" class="btn btn-default" id="select">选择</a>
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group">
                <div class="col-xs-4 col-xs-offset-3">
                    <button class="btn btn-primary" type="submit" id="tijiao">保存内容</button>
                </div>
            </div>
        </form>
    </div>
</div>

<!-- 全局js -->
{include file="Public/footer"}
<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
<script src="__STATIC__/layout/js/plugins/layer/layer.min.js"></script>
<script>
    $(function () {
        $('body').on('click','.renyuan span.close',function () {
            $(this).parent('.ren').remove();
        })
//        选择管理人员
        $('#select').on('click',function () {
            var index = layer.getFrameIndex(window.name)
            //iframe层-父子操作
            layer.open({
                type: 2,
                title: '请选择业务人员',
                area: ['500px', '400px'],
                fixed: false, //不固定
                maxmin: true,
                content: '{:url("selectsalesman")}?frameindex='+index
            });
            return false
        })

        /**
         * 测试(首次从 URL 获取数据，显示 header，不显示按钮，忽略大小写，可清除)
         */
        $("#testNoBtn").bsSuggest({
            url: "{:url('provicejson')}",
            /*effectiveFields: ["userName", "shortAccount"],
            searchFields: [ "shortAccount"],*/
            effectiveFieldsAlias:{userName: "姓名"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        }).on('onDataRequestSuccess', function (e, result) {
            console.log('onDataRequestSuccess: ', result);
        }).on('onSetSelectValue', function (e, keyword, data) {
            $(this).val('')
            var bool = false
            $('#renyuan .ren').each(function (idx,o) {
                if($(this).data('id') == keyword.id){
                    bool = true;
                }
            })
            if(bool == false)
                $('#renyuan').append('<span class="ren" data-id="'+keyword.id+'">'+keyword.key+'<span class="close">×</span></span>')
            //console.log('onSetSelectValue: ', keyword, data);
        }).on('onUnsetSelectValue', function () {
            console.log("onUnsetSelectValue");
        });
        
        $('#tijiao').on('click',function () {
            var form = $('#add')
            var admin = []
            $('#renyuan .ren').each(function (idx,o) {
                admin.push($(o).data('id'))
            })
            var admin2 = ''
            if(admin)
                admin2 = admin.join(',')
            $.ajax({
                'type':'post',
                'url':form.attr('action'),
                'data':{stuff:admin2},
                'dataType':'json',
                'success':function (data) {
                    if(data.success){
                        swal({
                            title: data.msg,
                            type: "success"
                        },function(){
                            parent.layer.close(parent.layer.getFrameIndex(window.name))
                        });

                    }else
                        swal({
                            title: data.msg,
                            type: "warning"
                        });
                }
            })
            return false
        })
    })
</script>
</body>

</html>